﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;

namespace Api.Web.helper
{
    public abstract class ViewPage<TModel> : System.Web.Mvc.WebViewPage<TModel>
    {

        public int projectId = Th.ProjectId, userId = Th.UserId;

        private string Translate(string strHtml)
        {
            Regex regex = new Regex(@"\[[-0-9a-zA-Z]+\]");
            var matchs = regex.Matches(strHtml);
            if (matchs.Count > 0)//匹配到
            {
                var flagList = new List<string>(matchs.Count);
                foreach (Match match in matchs)//循環收集標識
                {
                    flagList.Add(match.Groups[0].Value.Replace("[", "").Replace("]", ""));
                }

                foreach (var item in flagList)
                {
                    //var value = ModuleTranslate.Get(item);
                    //strHtml = strHtml.Replace(string.Format("[{0}]", item), value);
                }
            }
            return strHtml;
        }



        public override void ExecutePageHierarchy()
        {
            // Replace output stream with a fake local stream
            StringWriter fakeOutput = new StringWriter();

            // Save output stack top level stream, and replace with fake local stream
            TextWriter outputStackTopOutput = OutputStack.Pop();
            OutputStack.Push(fakeOutput);

            // Run Razor view engine
            base.ExecutePageHierarchy();

            string content = fakeOutput.ToString();

            //content = Translate(content);
            // Set back real outputs, and write to the real output 
            OutputStack.Pop();
            OutputStack.Push(outputStackTopOutput);
            outputStackTopOutput.Write(content);
        }
    }
}